#include <openssl/evp.h>
#include <string.h>


int main(){
    unsigned char data[128] = "20191305ltq";
    int data_size = strlen((char*)data);

    //初始化EVP上下文
    EVP_MD_CTX *ctx = EVP_MD_CTX_new();
    //掉用EVP简化接口编码 国密SM3
    unsigned char out[64] = { 0 };
    unsigned int out_size = 0;
    EVP_Digest(data, data_size, out, &out_size, EVP_sm3(), NULL);
    printf("%s\n",data);
    printf( "国密SM3：");
    int i;
    for ( i = 0; i < 64; i++)
    {
        printf("%x",out[i]);
    }
    printf(" ( %d)\n",out_size);
    // PrintHex(string(out, out + out_size));

}


    /*
    const EVP_MD *EVP_md5(void);
    const EVP_MD *EVP_sha1(void);
const EVP_MD *EVP_sha224(void);
const EVP_MD *EVP_sha256(void);
const EVP_MD *EVP_sha384(void);
const EVP_MD *EVP_sha512(void);
const EVP_MD *EVP_sha512_224(void);
const EVP_MD *EVP_sha512_256(void);
const EVP_MD *EVP_sha3_224(void);
const EVP_MD *EVP_sha3_256(void);
const EVP_MD *EVP_sha3_384(void);
const EVP_MD *EVP_sha3_512(void);
const EVP_MD *EVP_shake128(void);
const EVP_MD *EVP_shake256(void);
const EVP_MD *EVP_sm3(void); //1.1.1 版本开始支持
    */
    // const EVP_MD *evp_md = EVP_sha3_512();

    // //hash初始化
    // EVP_DigestInit_ex(ctx, evp_md, NULL);

    // //计算hash值
    // EVP_DigestUpdate(ctx, data, data_size);


    // // //获取结果
    // unsigned char out[64] = { 0 };
    // unsigned int out_size = 0;
    // EVP_DigestFinal_ex(ctx, out, &out_size);

    // printf( "SHA3-512:");
    // int i;
    // for ( i = 0; i < 64; i++)
    // {
    //     printf("%x",out[i]);
    // }
    
    // printf(" ( %d)\n",out_size);
    // // PrintHex(string(out, out + out_size));

    // //清理上下文
    // EVP_MD_CTX_free(ctx);